<?php 
/* 
Template Name: Manager product set
*/
?>
<?php 
//$current_user;
global $current_user;
get_currentuserinfo();
?>
<?php 
 if ( !is_user_logged_in() ) 
    {
      ?>

       
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
       
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
elseif (is_user_logged_in() )  
 { 
get_header(); 
    if (  ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
        ?>

        
              <?php wp_die( __( 'Vui lòng  quay lai trang chủ ! ' ) ); ?>
       
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {

        //echo 'hoang phuc duoc phep';
     ?>

<div id="content_nano_two" class="clearfix">
<?php 


   global $id_prod ;

   

   // $id_prod = array();
    if (isset($_GET['id'])) 
   {
      $id_prod=$_GET['id'];


   }

   if (isset($_POST['phanquyen'])) 
   {
     $id_prod = $_POST['phanquyen'];  // ID CUA MAY CAN PHAN QUYEN
     $sql_may = "SELECT * FROM wp_may WHERE id_may =".$id_prod;
     $array_may = $wpdb->get_row("SELECT * FROM wp_may WHERE id_may =".$id_prod, ARRAY_A);
     //var_dump($array_may);
   }
?>


  <div id="dialog-form-them-quan-tri" >
    <a id="popupClose">x</a>
    <h1>Thêm người quản lí</h1>
        <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>        
               <table class="wp-list-table widefat fixed users" cellspacing="0">
                    <thead>
                     <tr>
                       <th scope="col" id="cb"  style=""> </th>
                       <th scope="col" id="username"  style="width: 100px;"> <span>Tài khoản</span></th>
                       <th scope="col" id="name"   style="width: 150px;"><span>Tên người dùng</span></th>
                       <th scope="col" id="thaotac" style=""></th>
                     </tr>
                    </thead>
                    

                     <tbody id="the-list" data-wp-lists="list:user">
        <?php $rows = $wpdb->get_results($query_user);
             foreach($rows as $post)
             {

                 // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$post->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                        {
                                                       
                      if ( ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' )  ) //or ( $vlue ->meta_value == 'a:1:{s:13:"administrator";b:1;}')
                             
                             {
         ?>
              <tr id="user-<?php $post->ID; ?>" class="alternate">
                   <th scope="row" class="check-column">
                   </th>
                     <td class="username column-username">
                       <strong><?php echo $post->user_nicename;?></strong>
                    </td>
                    <td class="name column-name"><?php echo $post->display_name;?> </td>
                    <td class="thaotac column-thaotac">
                           <ul style='position: relative;'>
                                <li style='height: 20px;'>
                                     <input type='checkbox' 
                                       nqlisetadmin="<?php echo $post->ID; ?>"
                                       idmaysetadmin="<?php echo $id_prod;?>" 
                                      id="delqli" 
                                      class="addsetqli<?php echo $post->ID; ?>" 
                                      value='<?php echo $post->ID; ?>' style='z-index: 1997;'
                                      name='addsetqli<?php echo $post->ID; ?>'
                                      />
                                     </li>
                           </ul>

                    </td>
                                                   
                </tr><!-- id="user-xyz" class="alternate" -->
        <?php
      }// if ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}') 
   } //  foreach ($id_user_meta_data as $key =>$vlue) 
  } // end foreach($rows as $post) ?>
        

         </tbody>
                </table>

  <button id='guidulieudi' class="button action" style=" color:#555; padding:4px;margin-left: 258px; margin-top: 10px;" >Thêm người quản lí</button>
  <script type="text/javascript">
           
               jQuery(document).ready(function()
                    {               
                                     var person=[];
                                   
                                    $("td input[name^='addsetqli']").change(function() 
                                    {
                                    var  nqlisetadmin = $(this).attr("nqlisetadmin");
                                    var idmaysetadmin = $(this).attr("idmaysetadmin");
                                   
                                   person.push('/'+nqlisetadmin +'/'+ idmaysetadmin +'/');
                                  
                                  
                                   // alert(nqlisetadmin);
                                   // alert(idmaysetadmin);
                                    //return;

                                   // var users = [];
                                    function addUser(nqlisetadmin) 
                                    {
                                        var id = person.indexOf(null);
                                        if (id > -1) {
                                            // found an empty slot - use that
                                            person[id] = nqlisetadmin;
                                           // person[id +1]= idmaysetadmin;
                                            return id;
                                        } else {
                                            // no empty slots found, add to the end and return the index
                                            person.push(nqlisetadmin);
                                            return person.length - 1;
                                        }
                                    }
                                    function removeUser(id) {
                                        person[id] = null;
                                    }

                                     // alert(person);
                                     // return;

                                    });

                

       
                               $('#guidulieudi').click(function(event) {
                                      $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_them_set_admin_qlimay",
                                              type:"POST",
                                              data: {person:person},
                                              success: function(data)
                                              {
                                                //alert(data);
                                                $('#content_addqli').html(data);
                                                window.disablePopupphuc();
                                                //load_data(nqlisetadmin);
                                                //debugger;
                                              }
                                        });
                                    });
                           })
                            
                </script>  

      
</div><!-- id="dialog-form-them-quan-tri" title="Chọn thêm người phân quyền" -->



 <div style='margin:20px;'></div>

<div class="clearfix" style='min-height: 500px;'><!-- id="container" style="min-height: 606px;" -->
      <section class="tabs" style="min-height: 606px;">

<?php 

 if (  ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') or ( $current_user->roles[0] == 'editor') ) 
      {

        ?>
        <!--
        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php //wp_die( __( 'Vui lòng  quay lai trang chủ ! ' ) ); ?>
        </div>
         -->
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') or ( $current_user->roles[0] != 'editor')  )
      {

        //echo 'hoang phuc duoc phep';
  
     ?>


        <input id="tab-1" type="radio" name="radio-set" class="tab-selector-1" checked="checked" />
        <label for="tab-1" class="tab-label-1">Người quản lí </label>

    <?php 
    } // elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
    ?>



    
        <input id="tab-2" type="radio" name="radio-set" class="tab-selector-2" <?php if ( $current_user->roles[0] == 'editor') { ?> checked="checked"  <?php } ?> />
        <label for="tab-2" class="tab-label-2">Người dùng</label>
    
        <div class="clear-shadow"></div>
        
        <div class="content" style="min-height: 606px;" >

 <?php 

     if (  ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') or ( $current_user->roles[0] == 'editor') ) 
          {

            ?>
            <!--

            <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
                  <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
                  <?php //wp_die( __( 'Vui lòng  quay lai trang chủ ! ' ) ); ?>
            </div>
            -->
         <?php 

          }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
          elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') or ( $current_user->roles[0] != 'editor')  )
          {

            //echo 'hoang phuc duoc phep';
      
         ?>

            <div class="content-1" style="min-height: 606px;">
                <h2>Người quản lí</h2>
                <span class='buttonspan'>
                  <button class="hoanghalangqli" style="padding: 4px;margin-bottom: 5px;color: #555;position: relative;z-index: 1996;float: left;left: 0px;">Thêm người quản lí</button>
                </span>
                <span id='viewmay'>
                    <?php if ($array_may['image_may_url'] !=='') 
                    {
                      ?>
                       <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' src="<?php echo get_bloginfo('template_directory').'/upload_may/images/'.$array_may['image_may_url']; ?>">
                      <?php
                    }else { ?>
                            <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' 
                            src="<?php echo get_bloginfo('template_directory').'/images/no_image.gif';?>">
                     <?php } ?>
                      <h1 style='float:left; float: left;margin-left: 8px;margin-top: 30px;'><?php echo $array_may['name_may'];?></h1>
                  </span><!-- id='viewmay' -->

                 <span id='content_addqli'>
                  <!-- noi dung viet o day -->
                   <p>
                          
                    <?php 
                      $sql = "SELECT * FROM wp_user_wp_may
                                                                      INNER JOIN wp_users
                                                                                  ON wp_users.ID = wp_user_wp_may.ID
                                                                                  WHERE id_may =".$id_prod."";  
                                              
                                            $row = $wpdb->get_results($sql);
                                                            
                                                              ?> 
                                                             <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                                  <thead>
                                                                   <tr>
                                                                     <th scope="col" id="cb"  style=""> </th>
                                                                     <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                                     <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                                     <th scope="col" id="xoang"style=""></th>
                                                                   </tr>
                                                                  </thead>
                                                                   <tbody id="the-list" data-wp-lists="list:user">
                                                      <?php 
                                                        foreach($row as $key=>$value)
                                                       {
                                                        //var_dump($value);//break;

                                                         // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                           if ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}'  ) // or $vlue ->meta_value == 'a:1:{s:13:"administrator";b:1;}'
                             {
                                                       ?>
                                                            <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                                 <th scope="row" class="check-column">
                                                                   <label class="screen-reader-text" for="cb-select-1"></label>
                                                                 </th>
                                                                   <td class="username column-username">
                                                                     <strong><?php echo $value->user_login;?></strong>
                                                                  </td>
                                                                  <td class="name column-name"><?php echo $value->display_name;?></td>
                                                                  <td class="xoang column-xoang">
                                                                    <ul style='position: relative;'>
                                                                      <li style='height: 20px;'>
                                                                        <input type='button' 
                                                                        nguoiquanli="<?php echo $value->ID; ?>"
                                                                        idmay="<?php echo $id_prod;?>" 
                                                                        id="delqli" 
                                                                        class="delqli<?php echo $value->ID; ?>" 
                                                                        value=' Xóa' style='z-index: 1986;'
                                                                        name='delqli<?php echo $value->ID; ?>'
                                                                        />
                                                                      </li>
                                                                    </ul>
                                                                    <!-- onclick="if (!confirm("Bạn không xóa máy này ? chọn Click OK . Nếu bạn muốn xóa chọn HỦY")) return false;"  -->    
                                                                  </td>
                                                            </tr><!-- id="user-xyz" class="alternate" -->
                                                      <?php 
                        }// if ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}') 
                    } // foreach ($id_user_meta_data as $key =>$vlue)            
                }// foreach($row as $key=>$value)
                                                        ?>

                                                        
                                                             </tbody>
                                                                    </table>

                                    <!-- </div><!-- id='moidauload' -->
                                        
                            </p>
                 </span><!--content_addqli -->
               

              <div id="backgroundPopupqli"></div><!-- id="backgroundPopup" --> 
               
                 <script type="text/javascript">
                            
                               jQuery(document).ready(function(){

                                    $("td input[name^='delqli']").click(function() {
                                    var nguoiquanli = $(this).attr("nguoiquanli");
                                    var idmay = $(this).attr("idmay");
                                   
                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_xoa_may",
                                              type:"POST",
                                              data: {nguoiquanli:nguoiquanli,idmay:idmay},
                                              success: function(data)
                                              {
                                                $('#content_addqli').html(data);
                                                $('#content_addqli').show();
                                                $('#content_addqli').css('z-index','20001');
                                                //$('.wp-list-table.widefat.fixed.users').css('display','none');
                                                //$('.wp-list-table.widefat.fixed.users').css('width','800px');
                                               }
                                        });
                                    });
                                      
                                  })
                            
                </script>

      <script type="text/javascript">
                  /***************************/
                  //@Author: PHUC IT
                  //@website: www.maybanhang.net
                  //@email: phuca4@gmail.com
                  /***************************/
                           var popupphuc = 0;

                            function loadPopupphuc(){
                              if(popupphuc==0){
                                $("#backgroundPopupqli").css({
                                  "opacity": "0.7"
                                });
                                $("#backgroundPopupqli").fadeIn("slow");
                                $("#dialog-form-them-quan-tri").fadeIn("slow");

                                // bo check input 
                                $('#dialog-form-them-quan-tri').find(':checked').each(function() 
                                      {
                                       $(this).removeAttr('checked');
                                    });
                                popupphuc = 1;
                              }
                            }

                            function disablePopupphuc(){
                              if(popupphuc==1){
                                $("#backgroundPopupqli").fadeOut("slow");
                                $("#dialog-form-them-quan-tri").fadeOut("slow");
                                popupphuc = 0;
                              }
                            }

                            
                        

                           //load_data_set_nguoidung_cua_admin(setnguoidung,idmaysetnguoidung);
                         function load_data_set_nguoidung_cua_admin(idmayngdung) 
                                  {
                                    
                                    var idmayngdung = idmayngdung;
                                    //alert(idmayngdung);
                                      $.ajax({
                                              url:"<?php bloginfo('url');?>/process_load_user_nguoi_dung_la_admin",
                                              type:"POST",
                                              data: {idmayngdung:idmayngdung},
                                              dataType:"JSON",
                                              success: function(data_user_nd)
                                              {
                                               // alert(data_user_nd);
                                               // debugger;
                                               // return;
                                               var setnguoidunglaadmin = [];
                                               $.each(data_user_nd, function(key,value)
                                                {
                                                  setnguoidunglaadmin.push('<li>' + key + 'ID: ' + value.ID + 'id_may : ' + value.id_may + 'user_login : ' + value.user_login + '<li>');
                                               });
                                               $('<ul/>',{html:setnguoidunglaadmin.join('')}).appendTo('#phanquyennguoidungadmin');
                                               $('.content-2 .wp-list-table.widefat.fixed.users').css('display','none');
                                               $('.content-2').css({ position: 'absolute', left: '9000000'});
                                               $('.content-1 .wp-list-table.widefat.fixed.users').css('display','none');
                                               $('#content_addqli').css('width', '960');
                                               $('#content_addqli').css('position', 'relative');
                                               $('#content_addqli').css('z-index', '2003');
                                               $('.content-1 .wp-list-table.widefat.fixed.users').css('z-index', '2001');
                                               $('.content-2').css('min-height', '0');
                                               $('.content div').css({
                                                  position: 'relative',
                                                  overflow: 'none'
                                                });

                                               }
                                        });
                                  }


                            //centering popup
                            function centerPopuppphuc(){
                              //request data for centering
                              var windowWidth = document.documentElement.clientWidth;
                              var windowHeight = document.documentElement.clientHeight;
                              var popupHeight = $("#dialog-form-them-quan-tri").height();
                              var popupWidth = $("#dialog-form-them-quan-tri").width();
                              

                              $("#dialog-form-them-quan-tri").css({
                                "position": "absolute",
                                "top": windowHeight/2-popupHeight/2,
                                "left": windowWidth/2-popupWidth/2
                              });
                              
                              $("#backgroundPopupqli").css({
                                "height": windowHeight
                              });
                            }

                            // jQuery(document).ready(function()
                            jQuery(document).ready(function(){
                              
                               $(".hoanghalangqli").click(function(){
                                //centering with css
                                centerPopuppphuc();
                                //load popup
                                loadPopupphuc();
                              });
                                    
                              //CLOSING POPUP
                              //Click the x event!
                              $("#popupClose").click(function(){
                                disablePopupphuc();
                              });
                              //Click out event!
                              $("#backgroundPopupqli").click(function(){
                                disablePopupphuc();
                              });
                              //Press Escape event!
                              $(document).keypress(function(e){
                                if(e.keyCode==27 && popupphuc==1){
                                  disablePopupphuc();
                                }
                              });

                            });
                            
                </script>

            </div><!-- class="content-1" -->
     <?php 
    } // elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
    ?>

    <?php 
    if (( $current_user->roles[0] == 'administrator')) 
    {
      ?> 
     
         <div class="content-2" style="min-height: 606px;">
                <h2>Người dùng</h2>
                <?php // echo ' Admintrator';?>
                 <button id="Admintrator" style="padding: 4px;margin-bottom:5px;color: #555;" role="button">Thêm người dùng</button> 

                  <span id='viewmay'>
                    <?php if ($array_may['image_may_url'] !=='') 
                    {
                      ?>
                       <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' src="<?php echo get_bloginfo('template_directory').'/upload_may/images/'.$array_may['image_may_url']; ?>">
                      <?php
                    }else { ?>
                            <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' 
                            src="<?php echo get_bloginfo('template_directory').'/images/no_image.gif';?>">
                     <?php } ?>
                      <h1 style='float:left; float: left;margin-left: 8px;margin-top: 30px;'><?php echo $array_may['name_may'];?></h1>
                  </span><!-- id='viewmay' -->
                 
                <span id='phanquyennguoidungadmin'>
                 <?php
                    $sql = "SELECT wp_user_wp_may.ID,wp_user_wp_may.id_may,wp_users.ID,wp_users.user_login
                            FROM wp_user_wp_may
                            INNER JOIN wp_users
                            ON wp_users.ID = wp_user_wp_may.ID
                            WHERE wp_user_wp_may.id_may = ".$id_prod ;
                                                //echo $sql ;
                                                 $row = $wpdb->get_results($sql);
                                                 //var_dump($row );
                                                ?> 
                                               <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                    <thead>
                                                     <tr>
                                                       <th scope="col" id="cb"  style=""> </th>
                                                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                       <th scope="col" id="email"style=""></th>
                                                     </tr>
                                                    </thead>
                                                     <tbody id="the-list" data-wp-lists="list:user">
                                        <?php 
                                          foreach($row as $key=>$value)
                                         {


                                          $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                                                    foreach ($id_user_meta_data as $key =>$vlue) 
                                                    {
                                                       
                                                       if ( ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' )  ) // or ( $vlue ->meta_value == 'a:1:{s:13:"administrator";b:1;}')
                                                        {
                                                          ?>
                                                           <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                           <th scope="row" class="check-column">
                                                             <label class="screen-reader-text" for="cb-select-1"></label>
                                                           </th>
                                                             <td class="username column-username">
                                                               <strong><?php echo $value->user_login;?></strong>
                                                            </td>
                                                            <td class="name column-name"><?php echo $value->display_name;?></td>
                                                            <td class="email column-email">
                                                               
                                                               <ul style='position: relative;'>
                                                                <li style='height: 30px;'>
                                                                <input type="button" 
                                                                 nguoidung="<?php echo $value->ID; ?>" 
                                                                 idmay="<?php echo  $id_prod;?>"
                                                                 name="delng<?php echo $value->ID; ?>" 
                                                                 id="delnguoidung" 
                                                                 class="delnguoidung"
                                                                 value="Xóa"
                                                                 />
                                                               </li></ul>
                                                            </td>
                                                              </tr><!-- id="user-xyz" class="alternate" -->
                                                          <?php

                                                        } //  if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
                                                        
                                                    }//foreach ($id_user_meta_data as $key =>$vlue) 
            
                                              }// foreach($row as $key=>$value)
                                          ?>

                                   </tbody>
                             </table>
               </span><!-- id='phanquyennguoidungadmin' -->

      <div id="backgroundPopup"></div><!-- id="backgroundPopup" --> 

                 <script type="text/javascript">
                               jQuery(document).ready(function(){
                                    $("td input[name^='delng']").click(function() {
                                    var nguoidung = $(this).attr("nguoidung");
                                    var idmay = $(this).attr("idmay");
                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_admin_delngdung",
                                              type:"POST",
                                              data: {nguoidung:nguoidung,idmay:idmay},
                                              success: function(data)
                                              {
                                               // alert(data);
                                                $('#phanquyennguoidungadmin').html(data);

                                               /*
                                                window.disablePopup_adminbt();
                                                $('#backgroundPopup').css({
                                                  opacity: '0',
                                                  height: '0',
                                                  display:'none'
                                                });
                                               */
                                                $('#phanquyennguoidungadmin').show();
                                                //$('#backgroundPopup').css('opacity','0')

                                               }
                                        });
                                    });
                                      
                                  })
                             
                 </script>















                  <script type="text/javascript">
                  /***************************/
                  //@Author: PHUC IT
                  //@website: www.maybanhang.net
                  //@email: phuca4@gmail.com
                  /***************************/
                           var popupStatus = 0;

                            function loadPopup(){
                              if(popupStatus==0){
                                $("#backgroundPopup").css({
                                  "opacity": "0.7"
                                });
                                $("#backgroundPopup").fadeIn("slow");
                                $("#dialog-form-them-nguoi-dung").fadeIn("slow");
                                // bo check input 
                                $('#dialog-form-them-nguoi-dung').find(':checked').each(function() 
                                      {
                                       $(this).removeAttr('checked');
                                    });
                                popupStatus = 1;
                              }
                            }

                            function disablePopup(){
                              if(popupStatus==1){
                                $("#backgroundPopup").fadeOut("slow");
                                $("#dialog-form-them-nguoi-dung").fadeOut("slow");
                                popupStatus = 0;
                              }
                            }

                            //centering popup
                            function centerPopup(){
                              //request data for centering
                              var windowWidth = document.documentElement.clientWidth;
                              var windowHeight = document.documentElement.clientHeight;
                              var popupHeight = $("#dialog-form-them-nguoi-dung").height();
                              var popupWidth = $("#dialog-form-them-nguoi-dung").width();
                              

                              $("#dialog-form-them-nguoi-dung").css({
                                "position": "absolute",
                                "top": windowHeight/2-popupHeight/2,
                                "left": windowWidth/2-popupWidth/2,
                              });
                              
                              $("#backgroundPopup").css({
                                "height": windowHeight
                              });
                            }

                            // jQuery(document).ready(function()
               jQuery(document).ready(function(){
                              
                              $("#adduserngdung").click(function(){
                                //centering with css
                                centerPopup();
                                //load popup
                                loadPopup();
                              });
                                    
                              //CLOSING POPUP
                              //Click the x event!
                              jQuery("#popupCloseng").click(function(){
                                disablePopup();
                              });
                              //Click out event!
                              $("#backgroundPopup").click(function(){
                                disablePopup();
                              });
                              //Press Escape event!
                              $(document).keypress(function(e){
                                if(e.keyCode==27 && popupStatus==1){
                                  disablePopup();
                                }
                              });

                            });
                            
                </script>
                </p>
                
            </div><!-- class="content-2" -->
      <?php
    } //end admin

    if (( $current_user->roles[0] == 'editor')) 
    {

      ?>
        <div class="content-2" style="min-height: 606px;">
                <h2>Người dùng</h2>
                 <button id="adduserngdung" style="padding: 4px;margin-bottom:5px;color: #555;" role="button">Thêm người dùng</button>


 <?php  
global $current_user;
get_currentuserinfo();
$id_user_now = $current_user->ID;
//and ( $id_user_now === $value->ID ) 
?>

                  <span id='viewmay'>
                    <?php if ($array_may['image_may_url'] !=='') 
                    {
                      ?>
                       <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' src="<?php echo get_bloginfo('template_directory').'/upload_may/images/'.$array_may['image_may_url']; ?>">
                      <?php
                    }else { ?>
                            <img style='height: 100px; width: 100px; float:left; border-radius: 10px;' 
                            src="<?php echo get_bloginfo('template_directory').'/images/no_image.gif';?>">
                     <?php } ?>
                      <h1 style='float:left; float: left;margin-left: 8px;margin-top: 30px;'><?php echo $array_may['name_may'];?></h1>
                  </span><!-- id='viewmay' -->

          <span id ='phanquyenguoidungbinhthuong'>
                 <?php //echo 'dang la nguoi quan li'; ?>
                           <?php 
                            
                            $sql = "SELECT * FROM wp_user_wp_may
                                                        INNER JOIN wp_users
                                                                    ON wp_users.ID = wp_user_wp_may.ID
                                                                    WHERE id_may =".$id_prod;  
                          
                             $row = $wpdb->get_results($sql);
                                                
                                                ?> 

                

                                               <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                    <thead>
                                                     <tr>
                                                       <th scope="col" id="cb"  style=""> </th>
                                                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                       <th scope="col" id="email"style=""></th>
                                                     </tr>
                                                    </thead>
                                                     <tbody id="the-list" data-wp-lists="list:user">
                                        <?php 
        foreach($row as $key=>$value)
            {
               
               // kiem tra co phai la nguoi quan li hien tai
            if ( $id_user_now != $value->ID ) 
            {
               // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                          if ( ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' )  )
                             {
                                         ?>
                                              <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                   <th scope="row" class="check-column">
                                                     <label class="screen-reader-text" for="cb-select-1"></label>
                                                   </th>
                                                     <td class="username column-username">
                                                       <strong><?php echo $value->user_login;?></strong>
                                                    </td>
                                                    <td class="name column-name"><?php echo $value->display_name;?></td>
                                                    <td class="email column-email">
                                                       
                                                       <ul style='position: relative;'>
                                                        <li style='height: 30px;'>
                                                        <input type="button" 
                                                         nguoidung="<?php echo $value->ID; ?>" 
                                                         idmay="<?php echo $id_prod;?>"
                                                         name="delng<?php echo $value->ID; ?>" 
                                                         id="delnguoidung" 
                                                         class="delnguoidung"
                                                         value="Xóa"
                                                      
                                                         />
                                                       </li></ul>
                                                         <!-- onclick="return confirm('Bạn không xóa máy này ?')"; -->
                                                    </td>
                                                                                         
                                                      </tr><!-- id="user-xyz" class="alternate" -->
                                        <?php
              }//  if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
          } //  foreach ($id_user_meta_data as $key =>$vlue) 
      }// if ( $id_user_now != $value->ID ) 

   }// foreach($row as $key=>$value)
                                          ?>

                                               </tbody>
                                                      </table>    
        </span><!-- id ='phanquyenguoidungbinhthuong' -->                  
<div id="backgroundPopup"></div><!-- id="backgroundPopup" --> 
                 <script type="text/javascript">

                    
                       
                               jQuery(document).ready(function(){

                                    $("td input[name^='delng']").click(function() {
                                    var idxoa = $(this).attr("nguoidung");
                                    var idmay = $(this).attr("idmay");
                                    //alert(nguoidung);
                                    //alert(idmay);
                                    //return;
                                    // remove user ra khoi set : nguoi dung --> dat lich
                                    //url:"<?php bloginfo('url');?>/prosessing_ngdung_notadmin",

                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_ngdung_notadmin",
                                              type:"POST",
                                              data: {idxoa:idxoa,idmay:idmay},
                                              success: function(data)
                                              {
                                                //alert(data);
                                                //load_set_user_ng(idmay);
                                                 $('#phanquyenguoidungbinhthuong').html(data);
                                              }
                                        });
                                    });
                                      
                                  })
                             
                 </script>


     <script type="text/javascript">
                  /***************************/
                  //@Author: PHUC IT
                  //@website: www.maybanhang.net
                  //@email: phuca4@gmail.com
                  /***************************/
                           var popupStatus = 0;

                            function loadPopup(){
                              if(popupStatus==0){
                                $("#backgroundPopup").css({
                                  "opacity": "0.7"
                                });
                                $("#backgroundPopup").fadeIn("slow");
                                $("#dialog-form-them-nguoi-dung").fadeIn("slow");
                                // bo check input 
                                $('#dialog-form-them-nguoi-dung').find(':checked').each(function() 
                                      {
                                       $(this).removeAttr('checked');
                                    });
                                popupStatus = 1;
                              }
                            }

                            function disablePopup(){
                              if(popupStatus==1){
                                $("#backgroundPopup").fadeOut("slow");
                                $("#dialog-form-them-nguoi-dung").fadeOut("slow");
                                popupStatus = 0;
                              }
                            }

                            //centering popup
                            function centerPopup(){
                              //request data for centering
                              var windowWidth = document.documentElement.clientWidth;
                              var windowHeight = document.documentElement.clientHeight;
                              var popupHeight = $("#dialog-form-them-nguoi-dung").height();
                              var popupWidth = $("#dialog-form-them-nguoi-dung").width();
                              

                              $("#dialog-form-them-nguoi-dung").css({
                                "position": "absolute",
                                "top": windowHeight/2-popupHeight/2,
                                "left": windowWidth/2-popupWidth/2,
                              });
                              
                              $("#backgroundPopup").css({
                                "height": windowHeight
                              });
                            }

                            // jQuery(document).ready(function()
               jQuery(document).ready(function(){
                              
                              $("#adduserngdung").click(function(){
                                //centering with css
                                centerPopup();
                                //load popup
                                loadPopup();
                              });
                                    
                              //CLOSING POPUP
                              //Click the x event!
                              jQuery("#popupCloseng").click(function(){
                                disablePopup();
                              });
                              //Click out event!
                              $("#backgroundPopup").click(function(){
                                disablePopup();
                              });
                              //Press Escape event!
                              $(document).keypress(function(e){
                                if(e.keyCode==27 && popupStatus==1){
                                  disablePopup();
                                }
                              });

                            });
                            
                </script>
                </p>
                
            </div><!-- class="content-2" -->

      <?php
    } // end editor
    ?>
           
            

        </div><!-- End div.content -->
    </section>
</div> <!-- id="container" -->









 <div id="them-nguoi-dung-bt-admintrator" title="Thêm người dùng" style="min-height: 90%;" >
  <a id="popupCloseadmin">x</a>
  <h1>Thêm người dùng</h1> <?php  //echo 'admin';?>
         <?php 
         $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
        // WHERE post_type='post'";
        ?>         
                 
                   <table class="wp-list-table widefat fixed users" cellspacing="0">
                        <thead>
                         <tr>
                           <th scope="col" id="cb"  style=""> </th>
                           <th scope="col" id="username"  style="width: 100px;"> <span>Tài khoản</span></th>
                           <th scope="col" id="name"  style="width: 150px;"><span>Tên người dùng</span></th>
                           <th scope="col" id="thaotac"style=""></th>
                         </tr>
                        </thead>
                        

                         <tbody id="the-list" data-wp-lists="list:user">

            <?php 
            $rows = $wpdb->get_results($query_user);
                 foreach($rows as $post)
                 {
                  // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$post->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                           if ( ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' ) ) // or ( $vlue ->meta_value == 'a:1:{s:13:"administrator";b:1;}') 
                             {
             ?>
                  <tr id="user-<?php $post->ID; ?>" class="alternate">
                       <th scope="row" class="check-column">
                       </th>
                         <td class="username column-username">
                           <strong><?php echo $post->user_nicename;?></strong>
                        </td>
                        <td class="name column-name"><?php echo $post->display_name;?> </td>
                        <td class="nguoidungadmin column-nguoidungadmin">
                               <ul style='position: relative;'>
                                    <li style='height: 20px;'>
                                         <input type='checkbox'                                            
                                           setnguoidungadmin="<?php echo $post->ID; ?>"
                                           idmaysetnguoidungadmin="<?php echo $id_prod;?>" 
                                          id="setnguoidungadminquanli" 
                                          class="addsetngdungadmin<?php echo $post->ID; ?> check" 
                                          value='<?php echo $post->ID; ?>' style='z-index: 2013;'
                                          name='addsetngdungadmin<?php echo $post->ID; ?>'
                                          />
                                         </li>
                               </ul>

                        </td>
                                                       
                    </tr><!-- id="user-xyz" class="alternate" -->
            <?php
                    }//if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
                 }//foreach ($id_user_meta_data as $key =>$vlue) 
             } // end foreach($rows as $post) ?>

             </tbody>
                    </table>
      <button id='themnguoidungqlinhieu' class="button action" style=" color: #555555;padding: 4px;margin-left: 266px; margin-top: 10px;" >Thêm người dùng</button><?php //echo'quanlis';?>

     <script type="text/javascript">
           
               jQuery(document).ready(function()
                    {               
                              
                               $('#themnguoidungqlinhieu').click(function(event) 
                               {
                                  var data_user_ngdung=[]; 
                                 
                                $( "#them-nguoi-dung-bt-admintrator .check:checked").each(function( index ) 
                                {
                                        //var data_user_ngdung=[];
                                        var setnguoidungadmin = $(this).attr("setnguoidungadmin");
                                        var idmaysetnguoidungadmin = $(this).attr("idmaysetnguoidungadmin");
                                        //alert('aaaa');
                                         data_user_ngdung.push('/'+setnguoidungadmin +'/'+ idmaysetnguoidungadmin +'/');

                                         //alert(data_user_ngdung);

                                });
                                //return;


                                      $.ajax({
                                              url:"<?php bloginfo('url');?>/prosessing_add_nguoid_bt_admin",
                                              type:"POST",
                                              data: {data_user_ngdung:data_user_ngdung},
                                              success: function(data)
                                              {
                                                //alert(data);

                                                  $('#phanquyennguoidungadmin').html(data);
                                                  $('#phanquyennguoidungadmin').show()
                                                   window.disablePopup_adminbt();
                                                   var data_user_ngdung=[];
                                                   //location.reload();
                                                  
                                              }
                                        });
                                    });
                           })
                            
                </script>     

           <script type="text/javascript">
                  /***************************/
                  //@Author: PHUC IT
                  //@website: www.maybanhang.net
                  //@email: phuca4@gmail.com
                  // dialogue add user nguoi dung do admin set
                  /***************************/
                           var adminbt = 0;

                            function loadPopup_adminbt()
                            {
                              if(adminbt==0)
                              {
                                $("#backgroundPopup").css({
                                  "opacity": "0.7"
                                });
                                $("#backgroundPopup").fadeIn("slow");
                                $("#them-nguoi-dung-bt-admintrator").fadeIn("slow");

                                // bo check input 
                                $('#them-nguoi-dung-bt-admintrator').find(':checked').each(function() 
                                      {
                                       $(this).removeAttr('checked');
                                    });


                                adminbt = 1;
                              }
                            }

                            function disablePopup_adminbt(){
                              if(adminbt==1)
                              {
                                $("#backgroundPopup").fadeOut("slow");
                                $("#them-nguoi-dung-bt-admintrator").fadeOut("slow");
                                adminbt = 0;
                              }
                            }

                            //centering popup
                            function centerPopup_adminbt(){
                              //request data for centering
                              var windowWidth = document.documentElement.clientWidth;
                              var windowHeight = document.documentElement.clientHeight;
                              var popupHeight = $("#them-nguoi-dung-bt-admintrator").height();
                              var popupWidth = $("#them-nguoi-dung-bt-admintrator").width();
                              

                              $("#them-nguoi-dung-bt-admintrator").css({
                                "position": "absolute",
                                "top": windowHeight/2-popupHeight/2,
                                "left": windowWidth/2-popupWidth/2,
                              });
                              
                              $("#backgroundPopup").css({
                                "height": windowHeight
                              });
                            }

                            // jQuery(document).ready(function()
               jQuery(document).ready(function(){
                              
                              $("#Admintrator").click(function()
                              {

                                //window.location.reload();
                                //centering with css
                                centerPopup_adminbt();
                                //load popup
                                loadPopup_adminbt();

                              });
                                    
                              //CLOSING POPUP
                              //Click the x event!
                              jQuery("#popupCloseadmin").click(function(){
                                disablePopup_adminbt();
                              });
                              //Click out event!
                              $("#backgroundPopup").click(function(){
                                disablePopup_adminbt();
                              });
                              //Press Escape event!
                              $(document).keypress(function(e){
                                if(e.keyCode==27 && adminbt==1){
                                  disablePopup_adminbt();
                                }
                              });

                            });
                            
                </script>
          
  
    </div><!-- id="dialog-form-them-nguoi-dung"-->


    <div id="dialog-form-them-nguoi-dung" title="Thêm người dùng" style="min-height: 90%;" >
  <a id="popupCloseng">x</a>
  <h1>Thêm người dùng</h1>

<?php 
global $current_user;
get_currentuserinfo();
$id_user_now = $current_user->ID;

//var_dump($id_user_now);
?>
         <?php 
         $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
        // WHERE post_type='post'";
        ?>         
                 
                   <table class="wp-list-table widefat fixed users" cellspacing="0">
                        <thead>
                         <tr>
                           <th scope="col" id="cb"  style=""> </th>
                           <th scope="col" id="username"  style="width: 100px;"> <span>Tài khoản</span></th>
                           <th scope="col" id="name"  style="width: 150px;"><span>Tên người dùng</span></th>
                           <th scope="col" id="thaotac" style=""></th>
                         </tr>
                        </thead>
                        

                         <tbody id="the-list" data-wp-lists="list:user">
            <?php $rows = $wpdb->get_results($query_user);
                 foreach($rows as $post)
                 {

                  
          // kiem tra co phai la nguoi quan li hien tai
            if ( $id_user_now != $post->ID ) 
            {
               
                  // truy van lay quyen quan tri
                   $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$post->ID);

                     foreach ($id_user_meta_data as $key =>$vlue) 
                         {
                                                       
                          if ( ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' )    )
                             {  //and ( $id_user_now === $post->ID )
                             
                             
                               ?>
                                    <tr id="user-<?php $post->ID; ?>" class="alternate">
                                         <th scope="row" class="check-column">
                                         </th>
                                           <td class="username column-username">
                                             <strong><?php echo $post->user_nicename;?></strong>
                                          </td>
                                          <td class="name column-name"><?php echo $post->display_name;?> </td>
                                          <td class="thaotac column-thaotac">
                                                 <ul style='position: relative;'>
                                                      <li style='height: 20px;'>
                                                           <input type='checkbox' 
                                                             setnguoidung="<?php echo $post->ID; ?>"
                                                             idmaysetnguoidung="<?php echo $id_prod;?>" 
                                                            id="setqli" 
                                                            class="setngdung<?php echo $post->ID; ?>" 
                                                            value='' style='z-index: 1997;'
                                                            name='setngdung<?php echo $post->ID; ?>'
                                                            />
                                                           </li>
                                                 </ul>

                                          </td>
                                                                         
                                      </tr><!-- id="user-xyz" class="alternate" -->
            <?php     
                         }//if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
                     } // foreach ($id_user_meta_data as $key =>$vlue) 
           }//( $id_user_now === $value->ID )
            } // end foreach($rows as $post) ?>

             </tbody>
                    </table>



      <button id='addnguoidung' class="button action" style=" color: #555555;padding: 4px;margin-left: 258px; margin-top: 10px;" >Thêm người dùng</button>
      <script type="text/javascript">


                                
         jQuery(document).ready(function(){
              var nguoidungdo =[]; 
               $("td input[class^='setngdung']").click(function() 
                    {
                       var  setnguoidung = $(this).attr("setnguoidung");
                       var idmaysetnguoidung = $(this).attr("idmaysetnguoidung");

                       nguoidungdo.push('/'+setnguoidung +'/'+ idmaysetnguoidung +'/'+ 'value :'+$(this).val() +'/');
                                     
                             // alert('setnguoidung');
                            //  alert(setnguoidung);
                                     
                             //  return;

                                       
                                      
                    });

                               $('#addnguoidung').click(function(event) {
                                       $.ajax({
                                                url:"<?php bloginfo('url');?>/prosessing_them_set_nguoi_qlimay",
                                                  type:"POST",
                                                  data: {nguoidungdo:nguoidungdo},
                                                  success: function(data){
                                                   // alert(data);
                                                  $('#sent').show();
                                                  $('#phanquyenguoidungbinhthuong').html(data);
                                                  $('#phanquyenguoidungbinhthuong').show()
                                                  // load_data_set_nguoidung(idmaysetnguoidung);
                                                  // debugger;
                                                   window.disablePopup();
                                                    // load lai du lieu voi tat ca cac may voi id user truyen vào 
                                                   

                                                                  }
                                            });
                                    });         

                            
                                          
                                      })

                  
                                
                    </script>     
          
  
    </div><!-- id="dialog-form-them-nguoi-dung"-->


    

</div><!-- id="content_nano_two" -->

<?php 
} //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) )  
?>
    
<?php get_footer(); ?>